<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>短信任务</title>
    <link type="text/css" href="/static/layui/v2.6.7/css/layui.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/static/layui/fromselect/formSelects-v4.css?v=0.0.2" media="all" />
    <script type="text/javascript" src="/static/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="/static/layui/v2.6.7/layui.js"></script>
    <link type="text/css" href="/static/layui/v2.6.7/css/layui-table.css" rel="stylesheet"/>
</head>

<body>
<div class="content">
    <div class="search">
        <div class="search_text">
            短信任务
        </div>
        <form action="/" method="get" class="layui-form search-form" id="search-form">
            <div class="layui-inline">
                <label class="layui-form-label">任务名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" id="title" placeholder="任务名称" value="{$param['title']}" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label>创建时间：</label>
                <div class="layui-input-inline" style="width: 160px;">
                    <input type="text" class="layui-input" name="starttime" id="starttime" value="{$starttime}" placeholder="yyyy-MM-dd" autocomplete="off">
                </div>
            </div>

            <div class="layui-inline">
                <button type="button" id="submit" class="layui-btn" lay-submit="" lay-filter="demo1">查询</button>
                <button type="button" id="add" class="layui-btn" lay-submit="" lay-filter="add">创建任务</button>
                <button type="button" id="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
    </div>
    <table id="totalList" lay-filter="totalList"></table>
</div>
<script>

    layui.use(['table', 'laydate','form'], function () {
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;

        laydate.render({
            elem: '#starttime',
            range: true
        });
        var tableIns = table.render({
            id: 'queryList'
            , url: '/?r=smsTask/index&mode=ajax&action=indexList'
            , loading: true
            , method:'post'
            , elem: '#totalList'
            , autoSort: false
            , cols: [[
                 { field: 'id', title: 'ID' , width: 80}
                , { field: 'title', title: '任务名称' , width: 150}
                , { field: 'type', title: '类型', width: 100}
                , { field: 'min_money_pay', title: '付费最小金额', width: 130}
                , { field: 'max_money_pay', title: '付费最大金额', width: 130}
                , { field: 'pay_num', title: '需要付费数', width: 130}
                , { field: 'pay_num_zero', title: '需要0元付费数', width: 130}
                , { field: 'send_pay_total', title: '付费实际发送数', width: 130}
                , { field: 'send_pay_zero_total', title: '0元实际发送数', width: 130}
                , { field: 'status', title: '状态', width: 100}
                , { field: 'note', title: '任务信息', width: 250}
                , { field: 'adminname', title: '操作人', width: 150}
                , { field: 'inserttime', title: '创建时间' , width: 150}
                , { field: 'updatetime', title: '最后更新时间' , width: 150}
                , { field: 'operate', title: '操作' , fixed: 'right', width: 160}
            ]]
            , page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
                limit: 15,
                limits: [15,30,50,100]
            }
            // ,toolbar: 'true ' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            // , defaultToolbar: ['filter', {
            //     title: '字段说明' //标题
            //     ,layEvent: 'LAYTABLE_TIPS' //事件名，用于 toolbar 事件中使用
            //     ,icon: 'layui-icon-tips' //图标类名
            // }]
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
        });

        form.on('submit(add)', function () {
            var uri = '/?r=smsTask/add&'+$("#search-form").serialize();
            var title = '创建短链';
            var index = layui.layer.open({
                title: title,
                type: 2,
                content: uri,
                area: ['1200px', '750px'],
                //iframe关闭后触发
                end: function (index, layero) {
                    $(".layui-laypage-btn")[0].click();
                },
            });
            return false;
        });


        table.on('sort(totalList)', function(obj){
            setSubmit(obj);
        });

        $("#export").click(function () {
            // setSubmit();
        });

        $('#submit').click(function () {
            setSubmit();
            setSubmitTask();
        });

        function setSubmit(obj){
            // var cols=tableIns.config.cols[0];
            var starttime = $('#starttime').val();
            var uri_key = $('#uri_key').val();

            tableIns.reload({
                autoSort: false
                ,where: { //设定异步数据接口的额外参数，任意设
                    uri_key: uri_key,
                    starttime: starttime,

                    // cols: JSON.stringify(cols)
                    field: obj==null ? "" : obj.field
                    ,order: obj==null ? "" : obj.type
                }
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        }


        $('#reset').click(function () {
            $('#starttime').val('');
            $('#title').val('');

            layui.form.render();
        });
    });


</script>
</body>
</html>
